﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq.SqlClient;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanhuaWin.工厂.仓库.报表
{
    public partial class Form调拨单查询 : UIPage
    {
        public Form调拨单查询()
        {
            InitializeComponent();
        }

        private void uiButton查询_Click(object sender, EventArgs e)
        {
          DataTable dt =  查询行(); 
            uiDataGridView2.DataSource = dt;
            uiDataGridView2.Refresh();
            decimal 总重 = 0;
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string 重量 = dt.Rows[i]["重量"].ToString();
                    decimal.TryParse(重量, out decimal 重);
                    总重 += 重;
                }
                uiTextBox总卷数.Text = dt.Rows.Count + "";
                uiTextBox总重.Text = 总重.ToString();
            }
        }

      
    

    private DataTable 查询行()
    {
        string sql = @"SELECT Bus_TransferV.shipno 船号,Bus_TransferV.DeliveryDate 发货日期, Bus_TransferV.CreateDate 制单日期,[VolumeNumber]   卷号,[InventoryCode]  存货编号 ,[Size]  规格  ,
                [Weight]   重量  ,[WarehouseName] 原仓库名, Bus_TransferVolume.[NewWarehouseName] 新仓库   ,[status] 状态,Bus_TransferVolume.[Modifier]    扫码人  ,
                Bus_TransferVolume.[ModifyDate]   扫码时间 ,[Chepai] 车牌
                 from Bus_TransferV left join Bus_TransferVolume
                on Bus_TransferVolume.guid = Bus_TransferV.guid where 1 = 1 ";

            if (string.IsNullOrEmpty(uiTextBox单号.Text.Trim()) == false)
            {
                sql += "and Bus_TransferV.DocCode like '%" + uiTextBox单号.Text.Trim() + "%' ";
            }
            if (string.IsNullOrEmpty(uiTextBox船号.Text.Trim()) == false)
            {
                sql += "and Bus_TransferV.shipno like '%" + uiTextBox船号.Text.Trim() + "%'";
            }
            if (checkEdit未发货.Checked == true)
            {
                sql += "and (Bus_TransferVolume.[Modifier] is null or Bus_TransferVolume.[Modifier] = '')";
            }

            sql += "and Bus_TransferV.DeliveryDate >='" + uiDatePicker开始日期.Value.ToString("yyyy-MM-dd") + "' and Bus_TransferV.DeliveryDate < '" + uiDatePicker结束日期.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
            sql += "order by Bus_TransferV.CreateDate desc";
            DataTable dt = pub.GetDataTable(pub.ConnectionString, sql);
            return dt;

        }

        private void Form调拨单查询_Load(object sender, EventArgs e)
        {
            uiDatePicker开始日期.Value = DateTime.Now;
            uiDatePicker结束日期.Value = DateTime.Now;

        }
    }
}
